package com.huawei.appmarket.service.externalapi.actions;

import android.app.Activity;
import android.view.KeyEvent;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.updatesdk.service.otaupdate.UpdateStatusCode.DialogButton;
import o.AccountBussinessListener;
import o.ccp;
import o.dyr;
import o.dys.a;
import o.eod;
import o.eoj;

public class LoginAction extends dyr {
    private static final int RESULTCODE_LOGIN_FAILED = 10002;
    private static final int RESULTCODE_LOGIN_SUCCESS = 10001;
    private static final String TAG = "LoginAction";
    private AccountBussinessListener accountObserver = new AccountBussinessListener(this) {
        final /* synthetic */ LoginAction ˋ;

        {
            this.ˋ = r1;
        }

        public void onAccountBusinessResult(ccp o_ccp) {
            if (102 == o_ccp.ˎ) {
                this.ˋ.callback.setResult(10001, null);
            } else if (DialogButton.CONFIRM == o_ccp.ˎ) {
                this.ˋ.callback.setResult(10002, null);
            }
            eoj.ˋ().ˊ(LoginAction.TAG);
            this.ˋ.callback.finish();
        }
    };

    public LoginAction(a aVar) {
        super(aVar);
    }

    public void onAction() {
        if (UserSession.getInstance().isLoginSuccessful()) {
            this.callback.setResult(10001, null);
            this.callback.finish();
            return;
        }
        eoj.ˋ().ˎ(TAG, this.accountObserver);
        eod.ॱ((Activity) this.callback);
    }

    public void cancelTask() {
        super.cancelTask();
        this.callback.setResult(10002, null);
    }

    public int onKeyDown(int i, KeyEvent keyEvent) {
        if (i == 4 && keyEvent.getRepeatCount() == 0) {
            this.callback.setResult(10002, null);
        }
        return super.onKeyDown(i, keyEvent);
    }
}
